﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FCS.GlobalComponents;

namespace FCS.Emulator
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        StartEmulator _se;

        public MainWindow()
        {
            InitializeComponent();
            
        }

        private void buttonStartEmulator_Click(object sender, RoutedEventArgs e)
        {
            // Make sure the data won't be read if it's not completed
            EmulatorUIManager._connectionData.isReady = false;

            // Display the data collection window
            _se = new StartEmulator();
            _se.Show(this);
            this.IsEnabled = false;


        }

        private void Window_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            // This will be called when opening or closing the connection data window
            if (EmulatorUIManager._connectionData.isReady)
            {
                // TODO: Start up the connection
                EmulatorUIManager.StartEmulator(AbstractUI());
            }
            // in false case we don't need to do anything.
        }

        private UIObjects AbstractUI() {
            UIObjects uio = new UIObjects();

            uio.HV = AbstractHV();
            uio.VV = AbstractVV();
            uio.northEnd = AbstractNorthEnd();
            uio.lights = AbstractLights();
            uio.pumps = AbstractPumps();
            uio.bollards = AbstractBollards();
            uio.environ = AbstractEnviron();
            uio.weirs = AbstractWeirs();
            uio.pumpVacuums = AbstractPumpVacuums();
            uio.northMister = AbstractNorthMister();
            uio.southMister = AbstractSouthMister();
            uio.northValveState = AbstractNorthValveState();
            uio.temperature = AbstractTemperature();

            return uio;
        }
        private UITrueFalse[] AbstractHV() {
            UITrueFalse[] hv = new UITrueFalse[FountainConstants.SouthEndValveCountPerCaliper];

            hv[(int)HV.H1] = new UITrueFalse(checkBoxH1);
            hv[(int)HV.H2] = new UITrueFalse(checkBoxH2);
            hv[(int)HV.H3] = new UITrueFalse(checkBoxH3);
            hv[(int)HV.H4] = new UITrueFalse(checkBoxH4);
            hv[(int)HV.H5] = new UITrueFalse(checkBoxH5);
            hv[(int)HV.H6] = new UITrueFalse(checkBoxH6);
            hv[(int)HV.H7] = new UITrueFalse(checkBoxH7);
            hv[(int)HV.H8] = new UITrueFalse(checkBoxH8);
            hv[(int)HV.H9] = new UITrueFalse(checkBoxH9);
            hv[(int)HV.H10] = new UITrueFalse(checkBoxH10);
            hv[(int)HV.HC] = new UITrueFalse(checkBoxHC);
            hv[(int)HV.HR] = new UITrueFalse(checkBoxHR);

            return hv;
        }

        private UITrueFalse[] AbstractVV() {
            UITrueFalse[] vv = new UITrueFalse[FountainConstants.SouthEndValveCountPerCaliper];

            vv[(int)VV.V1] = new UITrueFalse(checkBoxV1);
            vv[(int)VV.V2] = new UITrueFalse(checkBoxV2);
            vv[(int)VV.V3] = new UITrueFalse(checkBoxV3);
            vv[(int)VV.V4] = new UITrueFalse(checkBoxV4);
            vv[(int)VV.V5] = new UITrueFalse(checkBoxV5);
            vv[(int)VV.V6] = new UITrueFalse(checkBoxV6);
            vv[(int)VV.V7] = new UITrueFalse(checkBoxV7);
            vv[(int)VV.V8] = new UITrueFalse(checkBoxV8);
            vv[(int)VV.V9] = new UITrueFalse(checkBoxV9);
            vv[(int)VV.V10] = new UITrueFalse(checkBoxV10);
            vv[(int)VV.VC] = new UITrueFalse(checkBoxVC);
            vv[(int)VV.VR] = new UITrueFalse(checkBoxVR);

            return vv;
        }
        private UITrueFalse[] AbstractNorthEnd()
        {
            UITrueFalse[] ne = new UITrueFalse[FountainConstants.NorthEndValveCount];

            ne[(int)NorthValves.N1] = new UITrueFalse(checkBoxN1);
            ne[(int)NorthValves.N2] = new UITrueFalse(checkBoxN2);
            ne[(int)NorthValves.N3] = new UITrueFalse(checkBoxN3);
            ne[(int)NorthValves.N4] = new UITrueFalse(checkBoxN4);
            ne[(int)NorthValves.N5] = new UITrueFalse(checkBoxN5);
            ne[(int)NorthValves.N6] = new UITrueFalse(checkBoxN6);
            ne[(int)NorthValves.N7] = new UITrueFalse(checkBoxN7);
            ne[(int)NorthValves.N8] = new UITrueFalse(checkBoxN8);
            ne[(int)NorthValves.N9] = new UITrueFalse(checkBoxN9);
            ne[(int)NorthValves.N10] = new UITrueFalse(checkBoxN10);
            ne[(int)NorthValves.N11] = new UITrueFalse(checkBoxN11);
            ne[(int)NorthValves.N12] = new UITrueFalse(checkBoxN12);
            ne[(int)NorthValves.N13] = new UITrueFalse(checkBoxN13);
            ne[(int)NorthValves.N14] = new UITrueFalse(checkBoxN14);
            ne[(int)NorthValves.N15] = new UITrueFalse(checkBoxN15);
            ne[(int)NorthValves.N16] = new UITrueFalse(checkBoxN16);
            ne[(int)NorthValves.N17] = new UITrueFalse(checkBoxN17);
            ne[(int)NorthValves.N18] = new UITrueFalse(checkBoxN18);
            ne[(int)NorthValves.N19] = new UITrueFalse(checkBoxN19);
            ne[(int)NorthValves.N20] = new UITrueFalse(checkBoxN20);
            ne[(int)NorthValves.N21] = new UITrueFalse(checkBoxN21);
            ne[(int)NorthValves.N22] = new UITrueFalse(checkBoxN22);
            ne[(int)NorthValves.N23] = new UITrueFalse(checkBoxN23);
            ne[(int)NorthValves.N24] = new UITrueFalse(checkBoxN24);

            return ne;
        }
        private UITrueFalse[] AbstractLights()
        {
            UITrueFalse[] li = new UITrueFalse[FountainConstants.LightCount];

            li[(int)Lights.L1] = new UITrueFalse(checkBoxL1);
            li[(int)Lights.L2] = new UITrueFalse(checkBoxL2);
            li[(int)Lights.L3] = new UITrueFalse(checkBoxL3);
            li[(int)Lights.L4] = new UITrueFalse(checkBoxL4);
            li[(int)Lights.L5] = new UITrueFalse(checkBoxL5);
            li[(int)Lights.L6] = new UITrueFalse(checkBoxL6);
            li[(int)Lights.L7] = new UITrueFalse(checkBoxL7);
            li[(int)Lights.L8] = new UITrueFalse(checkBoxL8);
            li[(int)Lights.L9] = new UITrueFalse(checkBoxL9);
            li[(int)Lights.L10] = new UITrueFalse(checkBoxL10);
            li[(int)Lights.L11] = new UITrueFalse(checkBoxL11);
            li[(int)Lights.L12] = new UITrueFalse(checkBoxL12);
            li[(int)Lights.L13] = new UITrueFalse(checkBoxL13);
            li[(int)Lights.L14] = new UITrueFalse(checkBoxL14);

            return li;
        }
        private UITrueFalse[] AbstractPumps()
        {
            UITrueFalse[] pu = new UITrueFalse[FountainConstants.PumpCount];

            pu[(int)Pump.P1] = new UITrueFalse(checkBoxPump1);
            pu[(int)Pump.P2] = new UITrueFalse(checkBoxPump2);
            pu[(int)Pump.P3] = new UITrueFalse(checkBoxPump3);
            pu[(int)Pump.P4] = new UITrueFalse(checkBoxPump4);

            return pu;
        }
        private UITrueFalse[] AbstractBollards()
        {
            UITrueFalse[] bo = new UITrueFalse[FountainConstants.BollardCount];

            bo[(int)Bollard.B1] = new UITrueFalse(checkBoxBollard1);
            bo[(int)Bollard.B2] = new UITrueFalse(checkBoxBollard2);
            bo[(int)Bollard.B3] = new UITrueFalse(checkBoxBollard3);
            bo[(int)Bollard.B4] = new UITrueFalse(checkBoxBollard4);
            bo[(int)Bollard.B5] = new UITrueFalse(checkBoxBollard5);

            return bo;
        }
        private UITrueFalse[] AbstractEnviron()
        {
            UITrueFalse[] en = new UITrueFalse[FountainConstants.ReportedEnvironmentalStates];

            en[(int)Environ.ManholeClosed] = new UITrueFalse(checkBoxMHole);
            en[(int)Environ.NorthDisable] = new UITrueFalse(checkBoxNHWare);
            en[(int)Environ.SouthDisable] = new UITrueFalse(checkBoxSHWare);
            en[(int)Environ.SidewalkOK] = new UITrueFalse(checkBoxSWWater);

            return en;
        }
        private UITrueFalse[] AbstractWeirs()
        {
            UITrueFalse[] we = new UITrueFalse[FountainConstants.WeirCount];

            we[(int)Weirs.Weir1] = new UITrueFalse(checkBoxWeir1);
            we[(int)Weirs.Weir2] = new UITrueFalse(checkBoxWeir2);
            we[(int)Weirs.Weir3] = new UITrueFalse(checkBoxWeir3);

            return we;
        }
        private UITrueFalse[] AbstractPumpVacuums()
        {
            UITrueFalse[] pv = new UITrueFalse[FountainConstants.PumpCount];

            pv[(int)Pump.P1] = new UITrueFalse(checkBoxPumpVacuum1);
            pv[(int)Pump.P2] = new UITrueFalse(checkBoxPumpVacuum2);
            pv[(int)Pump.P3] = new UITrueFalse(checkBoxPumpVacuum3);
            pv[(int)Pump.P4] = new UITrueFalse(checkBoxPumpVacuum4);

            return pv;
        }
        private UITrueFalse AbstractNorthMister()
        {
            return new UITrueFalse(checkBoxNMister);
        }
        private UITrueFalse AbstractSouthMister()
        {
            return new UITrueFalse(checkBoxSMister);
        }
        private UITrueFalse AbstractNorthValveState()
        {
            return new UITrueFalse(checkBoxNorthValve);
        }
        private UIInteger AbstractTemperature()
        {
            return new UIInteger(textBoxTemperature);
        }

    }
}
